/***************************************************************************//**
 * @file GUI/WidgetCGI.h
 * @author  Marek M. Cel <marekcel@mscsim.org>
 *
 * @section LICENSE
 *
 * Copyright (C) 2013 Marek M. Cel
 *
 * This file is part of MScSim. You can redistribute and modify it under
 * the terms of GNU General Public License as published by the Free Software
 * Foundation; either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.
 * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Further information about the GNU General Public License can also be found
 * on the world wide web at http://www.gnu.org.
 ******************************************************************************/
#ifndef WIDGET_CGI_H
#define WIDGET_CGI_H

////////////////////////////////////////////////////////////////////////////////

#include <CGI/CGI_Manager.h>

#include <QGridLayout>
#include <QWidget>

#include <osgQt/GraphicsWindowQt>
#include <osgViewer/CompositeViewer>

////////////////////////////////////////////////////////////////////////////////

/** This is widget wrapper for CGI. */
class WidgetCGI : public QWidget, public osgViewer::CompositeViewer
{
    Q_OBJECT

public:



    /** Constructor. */
    WidgetCGI( QWidget *parent = 0 );

    /** Destructor. */
    virtual ~WidgetCGI();

    /** */
    void update( double timeStep, const CGI_DataInp &dataInp, CGI_DataOut &dataOut );

    /** */
    inline void setCameraManipulatorExternal()
    {
        m_cgi->setExternalCameraManipulator();
        m_view->setCameraManipulator( m_cgi->getCameraManipulator().get() );
    }

    /** */
    inline void setCameraManipulatorInternal()
    {
        m_cgi->setInternalCameraManipulator();
        m_view->setCameraManipulator( m_cgi->getCameraManipulator().get() );
    }

protected:

    /** */
    void paintEvent( QPaintEvent *event );

private:

    CGI_Manager *m_cgi;
    QGridLayout *m_gridLayout;

    osg::ref_ptr<osgViewer::View> m_view;

    /** */
    QWidget * addViewWidget( osgQt::GraphicsWindowQt *graphicsWindow, osg::Node *scene );

    /** */
    osg::ref_ptr<osgQt::GraphicsWindowQt> createGraphicsWindow( int x, int y, int w, int h, const std::string &name = "", bool windowDecoration = false );
};

////////////////////////////////////////////////////////////////////////////////

#endif // WIDGET_CGI_H
